package com.iot08.api.service;

import com.iot08.api.utils.buckettool.BaseBucketTool;
import com.iot08.api.vo.request.ComplaintReportReqVO;
import com.iot08.api.vo.request.IdParamReqVO;
import com.iot08.common.entity.app.Complaint;
import com.iot08.common.entity.app.ComplaintReason;
import com.iot08.common.service.base.BaseService;
import com.iot08.common.utils.response.ResponseMap;
import lombok.extern.slf4j.Slf4j;
import org.bson.types.ObjectId;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * @version 1.0
 * @Description: 投诉记录
 * @author: Rock
 * @time: 2021/5/7 11:28
 */
@Slf4j
@Service
public class ComplaintService extends BaseService<Complaint> {

    @Resource
    private ComplaintReasonService complaintReasonService;
    @Resource
    private BaseBucketTool baseBucketTool;

    /**
     * @param vo
     * @param image1
     * @param image2
     * @param image3
     * @time: 2021/5/8 9:04
     * @author: Rock
     * @version 1.0
     */
    public ResponseMap report(ComplaintReportReqVO vo, MultipartFile image1, MultipartFile image2,
                              MultipartFile image3) throws IOException {
        Complaint complaint = new Complaint();
        List<String> images = new ArrayList<>();
        if (image1 != null && !image1.isEmpty()) {
            //上传图片
            String fileName = BaseBucketTool.createFileNameToJpg();
            baseBucketTool.upload(BaseBucketTool.VOICEALARM_COMPLAINT_PATH + fileName, image1, 1);
            images.add(fileName);
        }
        if (image2 != null && !image2.isEmpty()) {
            //上传图片
            String fileName = BaseBucketTool.createFileNameToJpg();
            baseBucketTool.upload(BaseBucketTool.VOICEALARM_COMPLAINT_PATH + fileName, image2, 1);
            images.add(fileName);
        }
        if (image3 != null && !image3.isEmpty()) {
            //上传图片
            String fileName = BaseBucketTool.createFileNameToJpg();
            baseBucketTool.upload(BaseBucketTool.VOICEALARM_COMPLAINT_PATH + fileName, image3, 1);
            images.add(fileName);
        }
        complaint.setImei(vo.getImei());
        complaint.setChatGroupId(vo.getChatGroupId());
        complaint.setImages(images);
        complaint.setOpenid(vo.getOpenid());
        complaint.setComplaintReasonId(vo.getId());
        complaint.setContent(vo.getContent());
        complaint.setCreateTime(System.currentTimeMillis() / 1000);
        this.save(complaint);
        return ResponseMap.success();
    }
}
